define(['core/boilerplate', "core/manager", "common/menu"], function(Boilerplate, Manager, Menu) {
	var MenuManager = new Manager(Menu);

	MenuManager._init = MenuManager.init;
	MenuManager.init = function(Mode) {
		todo('Définir le mode de rendu CANVAS pour les menus');

		this.displayMode = Mode === 'CANVAS' ? Mode : 'HTML';
		this._init(0);
	};

	MenuManager.caInit = function() {
		var that = this;
		switch (this.displayMode) {
			case 'HTML' :

				// Create Menu Container
				this.container = document.createElement('div');

				// Configure it
				this.container.id = 'menu_container';
				this.container.style.width = (Boilerplate.scene.width * Boilerplate.scene.coef) +'px';
				this.container.style.height = (Boilerplate.scene.height * Boilerplate.scene.coef) +'px';

				// Add it to page
				var body = document.getElementsByTagName("body")[0];
				body.appendChild(this.container);

			break;

			case 'CANVAS' : 
			break;

			default : 
		}

		this.addMenu('Main');
		this.addMenu('Settings');
		this.addMenu('Pause');
		this.switchToMenu('main_menu');	

		var menus = $(".menu_screen");

		for(var i = 0, c = menus.length; i < c; i++) {
			menus[i].style.width = (Boilerplate.scene.width * Boilerplate.scene.coef) +'px';
			menus[i].style.height = (Boilerplate.scene.height * Boilerplate.scene.coef) +'px';
		}

	};

	MenuManager.cbUpdate = function() {
		if(Boilerplate.controller.stop === true || Boilerplate.controller.pause === true) {
			var coef = 10,
				menus = $(".menu_screen"),
				sceneWidth = Boilerplate.scene.width * Boilerplate.scene.coef,
				sceneHeight = Boilerplate.scene.height * Boilerplate.scene.coef;

			for(var i = 0, c = menus.length; i < c; i++) {

				var width = parseUnits(menus[i].style.width),
					height = parseUnits(menus[i].style.height);
				
				if(isMobileDevice() === false && Math.abs(width - sceneWidth) >= percent(sceneWidth, 5)) {
					global_animate(menus[i], {'width': sceneWidth + 'px'}, 500);
				} else {
					menus[i].style.width = sceneWidth + 'px';
				}

				if(isMobileDevice() === false && Math.abs(height - sceneHeight) >= percent(sceneHeight, 5)) {
					global_animate(menus[i], {'height': sceneHeight + 'px'}, 500);
				} else {
					menus[i].style.height = sceneHeight + 'px';
				}
			}
		}
	};

	MenuManager.addMenu = function(Name) {
		this.entities.push(this.create(Name));
	};

	MenuManager.switchToMenu = function(ID) {
		switch (this.displayMode) {
			case 'HTML' :
				removeClass($('#'+this.container.id), 'hide');
				addClass($('.menu_screen'), 'hide');
				removeClass($('#'+ID+'_0'), 'hide');
			break;

			case 'CANVAS' : 
			break;

			default : 
		}
	};

	MenuManager.playGame = function() {
		Boilerplate.setPause(false);
		this.hideMenu();
	};

	MenuManager.pauseGame = function() {
		this.switchToMenu('pause_menu');
	};

	MenuManager.resumeGame = function() {
		Boilerplate.setPause(false);
		this.hideMenu();
	};

	MenuManager.quitGame = function() {
		this.switchToMenu('main_menu');
	};

	MenuManager.hideMenu = function() {
		switch (this.displayMode) {
			case 'HTML' :
				addClass($('.menu_screen'), 'hide');
				addClass($('#'+this.container.id), 'hide');
			break;

			case 'CANVAS' : 
			break;

			default : 
		}
	};

	MenuManager.functions = {
		SwitchToMenu : function() { var id = this.getAttribute('data-identifier'); MenuManager.switchToMenu(id); },
		Play : function() { MenuManager.playGame(); },
		Pause : function() { MenuManager.pauseGame(); },
		Resume : function() { MenuManager.resumeGame(); },
		Quit : function() { MenuManager.quitGame(); }
	};

	return MenuManager;
});